package com.example.demo.controller;


import com.example.demo.model.Course;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.demo.respository.CourseMapper;

import java.util.List;

@RestController
public class CourseController {
    @Autowired
    CourseMapper courseMapper;

    @GetMapping("/findAllCourse")
    public List<Course> findAllCourse(){
        return courseMapper.findAllCourse();
    }

    @GetMapping("/findById/{id}")
    public Course findCourseById(@PathVariable("id") int id){
        return courseMapper.findCourseById(id);
    }

    @DeleteMapping("/delete/{id}")
    public void deleteById(@PathVariable("id") int id){
        courseMapper.deleteCourse(id);
    }

    @PostMapping("/insertCourse")
    public void insertCourse(@RequestBody Course course )
    {
        courseMapper.insertCourse(course);
    }

    @PutMapping("/updateCourse")
    @ResponseBody
    public void updateEmp(@RequestBody Course c){
        int id = c.getCid();

        Course course = courseMapper.findCourseById(id);

        course.setCname(c.getCname());
        courseMapper.updateCourse(course);
    }
}
